import { FactoryTaskHelper } from "GameLoop/WorldState/EntityManager/Entitys/room/factory/FactoryTaskHelper";
import { BinaryDecision } from "framework/FSM/DecisionTree/Decision";

/**
 * 生产所需要的空间满足要求
*/
export class DecisionIsFactoryProduceSpaceEnough <T extends IStateArg<Room>> extends BinaryDecision<T>
{

    public testValue(arg:T): boolean
    {
 
        const toptask = arg.entity.getTaskByType("factory")[0]?.data ;
        
        const core = arg.entity.getEntity("CoreEntity");
        // 剩余的空间足够一次produce
        if(toptask && core.Factory)
        {
            const topproduce = FactoryTaskHelper.Top(toptask.arg);
            if(topproduce)
            {
                const subresource = FactoryTaskHelper.CalAllProduceAmount(topproduce.target);
                arg.entity.log("info",`生产目标:${topproduce.target} 工厂空间:${core.Factory.store.getFreeCapacity()}-> 需要空间:${subresource}`);
                if(core.Factory.store.getFreeCapacity()>= subresource)
                {
                    // 所有的反应物都可以放下 1.a
                    return true;
                }
                return false;
            }
            else
            {
                // 没有生产目标
                throw new Error(`${arg.entity.GUID} 生产列表为空`);
            }
            //

        }
        else
        {
            throw new Error(`${arg.entity.GUID} topreactiontask is null`);
        }
        // return false
    }

}

